//
//  CinemaViewController.m
//  ShowTimeApp
//
//  Created by Ruby on 10/20/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaTableViewController.h"
#import "MovieViewController.h"
#import "LibConvert.h"

@implementation CinemaViewController
@synthesize movieView,cinemaView,cinemaButtonSwitch,movieButtonSwitch;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(void)loadView{
    self.navigationItem.title=@"ShowtimeBox";
    [self initNavigationBar];
    self.navigationItem.leftBarButtonItem = self.cinemaButtonSwitch;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.view = [[UIView alloc]init];
    UIImageView *imageView = [[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg320x416_1.png"]] autorelease];
    imageView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 416.0f);
    [self.view addSubview:imageView];
    //self.navigationItem.rightBarButtonItem = self.movieButtonSwitch;
}

-(void)initNavigationBar{
    self.cinemaButtonSwitch = [[[UIBarButtonItem alloc]initWithTitle:@"Cinema" style:UIBarButtonItemStylePlain target:self action:@selector(switchView:)]autorelease];
     self.movieButtonSwitch=[[[UIBarButtonItem alloc]initWithTitle:@"Movie" style:UIBarButtonItemStylePlain target:self action:@selector(switchView:)]autorelease];
}

-(void)switchView:(id)sender{
    NSString* title = ((UIBarButtonItem*)sender).title;
    if(title==@"Movie"){
        MovieViewController *movieViewController = [[[MovieViewController alloc]init]autorelease];
        [self.navigationController pushViewController:movieViewController animated:YES];    
    }else{
        CinemaTableViewController *cinemaViewController = [[[CinemaTableViewController alloc]init]autorelease];
        cinemaViewController.tableView.backgroundColor= [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f];
        [self.navigationController pushViewController:cinemaViewController animated:YES];
    }
    //UIAlertView *messageBox = [[[UIAlertView alloc]initWithTitle:@"Hello" message:@"Hello Ruby" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]autorelease];
    //[messageBox show];
} 

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    UIImageView* iv = [[UIImageView alloc]init];
//    iv.image= [UIImage imageNamed:@"bg320x416.png"];
//    iv.frame= self.view.frame;
//    [self.view addSubview:iv];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
